<?php

namespace app\components;


use app\exception\BuyException;
use app\exception\ErrorCode;
use app\exception\OaException;
use app\service\UserService;
use yii\validators\Validator;

class Code1Validator extends Validator
{
    /**
     * @param \yii\base\Model $model
     * @param string $attribute
     * @throws BuyException
     */
    public function validateAttribute($model, $attribute)
    {
        $value = $model->$attribute;

        $redis = UserService::getRedis();
        $code = $redis->get($model->sessionId);


        if (strtolower($value)!=strtolower($code)) {
            throw new OaException(ErrorCode::CODE_ERR);
        }
    }
}